package test;

import com.tan.utils.DateUtils;
import org.junit.Test;

import com.tan.dom4japi.Dom4j;
import com.tan.dom4jdome.Dom4jImpl;
import com.tan.entity.InfoEntity;
import com.tan.utils.LogUtils;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;

public class AirlineText {
    private final String XML_PATH =System.getProperty("user.dir")+"/src/main/resources/av_with_airline_rs.xml";
    /**
     * @Author 谭永超 [www.tanyongchao.tk:8090/SumDome/index]
     * @Date 2018/8/16 10:14
     * @Description 获取到航班信息集合
     */
    // 有log4j的输出
    @Test
    public void test() throws Exception {
        Dom4j dom4j = new Dom4jImpl();
        List<InfoEntity> entities = dom4j.getInfoEntitys(XML_PATH);
        //System.out.println(entities.size());
        //dom4j.getInfoEntitys2(XML_PATH);
        List<InfoEntity> list =  dom4j.selectInfo("PEK","SHA",DateUtils.formatDate("2014-04-25"),XML_PATH);
        Collections.sort(list);
        for(InfoEntity infoEntity : list){
            System.out.println("date:"+ formatDate(infoEntity.getDepartureDate())+"  hour:"+formatTime(infoEntity.getDepartureTime())+"  FlightNumber:"+infoEntity.getFlightNumber());
            System.out.println();
        }
    }

    private static String formatTime(Date date) throws Exception {
        DateFormat format = new SimpleDateFormat("HH:mm");
        try {
            return format.format(date);
        } catch (Exception e) {
            LogUtils.LogInfo(AirlineText.class,"时间格式转换异常");
            throw e;
        }
    }
    private static String formatDate(Date date) throws Exception {
        DateFormat format = new SimpleDateFormat("YYYY-MM-dd");
        try {
            return format.format(date);
        } catch (Exception e) {
            LogUtils.LogInfo(AirlineText.class,"时间格式转换异常");
            throw e;
        }
    }
}
